package cn.yh.dwr;

import java.util.ArrayList;
import java.util.List;

import cn.yh.hibernate.City;
import cn.yh.hibernate.CityDAO;
import cn.yh.hibernate.Privinces;
import cn.yh.hibernate.PrivincesDAO;
import cn.yh.hibernate.Tone;
import cn.yh.hibernate.ToneDAO;

public class DWRpct {

	public List getPrivinces() {
		List<Privinces> l = new PrivincesDAO().findAll();
		List ll = new ArrayList();
		for (Privinces p : l) {
			ll.add("  " + p.getPnameCn() + "   ");
		}
		return ll;
	}

	public List getCity(String city) {
		city=city.trim();
		List lll= new PrivincesDAO().findByPnameCn(city);
		Privinces p1;
		if (lll != null) {
			p1 = (Privinces) lll.get(0);
		} else {
			return null;
		}
		List<City> l = new CityDAO().findByProperty("privinces", p1);
		List ll = new ArrayList();
		for (City p : l) {
			ll.add("  " + p.getCnameCn() + "   ");
		}
		return ll;
	}

	public List getTone(String tone) {
		tone=tone.trim();
		List lll = new CityDAO().findByCnameCn(tone);
		City c1 = null;
		if (lll != null) {
			c1 = (City) lll.get(0);
		} else {
			return null;
		}
		List<Tone> l = new ToneDAO().findByProperty("city", c1);
		List ll = new ArrayList();
		for (Tone p : l) {
			ll.add("  " + p.getTnameCn() + "   ");
		}
		return ll;
	}
}
